<?php

$cacheName = 'IDV10450.xml';

if (@$_GET['refresh'] == "1") {
	exec("wget --no-cache -N ftp://ftp2.bom.gov.au/anon/gen/fwo/IDV10450.xml");
	$xml = file_get_contents($cacheName);
	header('Content-type: application/xml');
	echo $xml;

} elseif (@$_GET['currenttemp'] == "1") {
	exec("wget --no-cache -N http://www.bom.gov.au/vic/observations/melbourne.shtml");
	$currTemp = file_get_contents("melbourne.shtml");
	
	if ($currTemp !== "") {
		$melbTemp = strpos($currTemp, "<td headers=\"obs-temp obs-station-melbourne-olympic-park\">");
		if ($melbTemp) {
			$i = 0;
			$nowTemp = "";
			$temp = "<td headers=\"obs-temp obs-station-melbourne-olympic-park\">";
			while ($i < 10) {
				$currTemp2 = substr($currTemp, $melbTemp+strlen($temp)+$i, 1);
				if ($currTemp2 == "<") {
					break;
				} else {
					$nowTemp .= $currTemp2;
				}
				$i++;
			}
			echo $nowTemp;
		}
	}
} else {
	$xml = file_get_contents($cacheName);
	header('Content-type: application/xml');
	echo $xml;
}

?>
